<?php

namespace App\Models\Scm;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class MaterialCategory extends Model
{
    use HasFactory;
    public $timestamps = FALSE;
    protected $table = 'biz_material_category';
    protected $fillable = ['id', 'pid', 'has_child', 'code', 'name', 'id_path', 'status', 'del_flag', 'tenant_id', 'kingdee_code', 'kingdee_id', 'create_time'];

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
    }

    public function insertOne($params){
        return self::create($params);
    }

    public function insertMany($params){
        return self::insert($params);
    }

    public function updateById($params, $id){
        return self::where("id", $id)->update($params);
    }

    public function findRowById($id){
        return self::whereRaw('BINARY id = ?', [$id])->first();
    }
    public function hasChild($id){
        $oneChild = self::where('pid', $id)->first();
        return $oneChild ? true : false;
    }
}
